package com.askinhand.action;

import javax.annotation.Resource;

import org.apache.struts2.json.annotations.JSON;

import com.askinhand.bean.User;
import com.askinhand.bean.UserInfo;
import com.askinhand.service.IUserService;
import com.opensymphony.xwork2.ActionSupport;

public class UserRegisterAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	
	IUserService userService;
	String strResult;
	String username;
	String name;
	String password;
	
	@JSON (serialize=false)
	public IUserService getUserService() {
		return userService;
	}

	@Resource
	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	
	@JSON (serialize=false)
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}

	@JSON (serialize=false)
	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	
	public String getStrResult() {
		return strResult;
	}
	public void setStrResult(String strResult) {
		this.strResult = strResult;
	}
	
	
	@JSON(serialize=false)
	public String getUsername() {
		return username;
	}
	public void setUsername(String userName) {
		this.username = userName;
	}
	@JSON(serialize=false)
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}

	public String execute(){
		User user = new User();
		user.setType(0);
		user.setUsername(username);
		user.setPassword(password);
		
		UserInfo userinfo=new UserInfo();
		userinfo.setUser(user);
		userinfo.setAge(20);
		userinfo.setEmail(null);
		userinfo.setGender(null);
		userinfo.setName(name);
		userinfo.setPhone(null);
		userinfo.setPpoints(0);
		userinfo.setSpoints(0);
		
		strResult = userService.register(user,userinfo);
		//strResult: fail or success
		return "success";
	}
}
